<?php

/**
 * Adding a Credentials
 * @package ModuleAdministratif
 * @version 1.0b
 * @return table td
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

try {
	// Creating credentials
	$credentials = new Credentials();
	foreach ($_POST as $key => $value)
		$credentials->$key = $value;
	
	// Inserting credentials into database
	$credentials->SaveNew();
	
	$msg  = '<tr><td class="del"><a href="'.$credentials->credentialsId.'" class="delete-doc delete-credentials"><img src="css/img/bin_empty.png" alt="Delete" /></a></td>';
	$msg .= '<td>'.$credentials->name.'</td></tr>';
	echo $msg;
	
} catch (Exception $e) {
	echo $e->getMessage();
}
?>